package com.apexsoft.monitor.front.console.index.controller;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.apexsoft.front.common.support.BaseFrontController;
import com.apexsoft.front.common.utils.SpringContextUtil;
import com.apexsoft.front.common.utils.session.UserSessionNoRedis;
import com.apexsoft.monitor.common.MonitorConstant;
import com.apexsoft.monitor.front.console.user.service.UserService;
import com.apexsoft.monitor.mq.LogMqSubscribe;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@Controller("IndexController")
@RequestMapping("/console/index")
public class IndexController extends BaseFrontController {

	@RequestMapping(value="/main")
	public String main(HttpServletRequest request,HttpServletResponse response, ModelMap modelMap) throws Exception
	{
		JSONObject userInfo = UserSessionNoRedis.getSessionObj(request, UserSessionNoRedis.CONSOLE_SESSION);
		if (userInfo != null) {
			String menuIds = (String)userInfo.get("menuIds");
			UserService userSvc = (UserService) SpringContextUtil.getBean("consoleUserService");
			JSONArray result = userSvc.getSystemMenuListByIds(menuIds);

			request.setAttribute("SYS_TITLE", MonitorConstant.SYS_TITLE);
			request.setAttribute("menuList", result);
			request.setAttribute("version", MonitorConstant.VERSION);
		}
		return "console/index/index";
	}
	@Deprecated
	@RequestMapping(value="/top")
	public String top(HttpServletRequest request,HttpServletResponse response, ModelMap modelMap) throws Exception
	{	
		return "console/index/top";
	}

	@RequestMapping(value="/content")
	public String content(HttpServletRequest request,HttpServletResponse response, ModelMap modelMap) throws Exception
	{
		return "console/index/content";
	}

	@RequestMapping(value="/getQueueSize")
	public String getQueueSize(HttpServletRequest request,HttpServletResponse response, ModelMap modelMap) throws Exception
	{
		int queueSize = LogMqSubscribe.queue.size();
		this.print(response,queueSize+"");
		return null;
	}

}
